package com.example.springdemo.controller;

import com.example.springdemo.domain.HelloWorld;
import com.example.springdemo.domain.JsonData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import util.LogFileName;
import util.LoggerUtils;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @ClassName Hello
 * @Description TODO
 * @Author MaChao
 * @Date 2022/2/21 17:15
 * @Version 1.0
 **/
@RestController
@Tag(name = "操作接口", description = "操作描述")
public class Hello {
    /*
        Logger logger = LoggerFactory.getLogger(Hello.class);
    */
    Logger USER = LoggerUtils.logger(LogFileName.USER);
    @Resource
    HelloWorld helloWorld;
    @Resource
    JsonData jsonData;

    @PostConstruct
    private void init() {
        helloWorld.setMag("操作成功");
        helloWorld.setStart(1);
        //helloWorld.setData(new JsonData("hellow world--88888"));
        helloWorld.setData(jsonData);
        /*logger.error("hello 已经初始化");*/
        USER.info("user 业务日志测试");
    }

    /*@RequestMapping("/hello")*/
    @GetMapping("hello")
    @ResponseBody
    @Operation(summary = "返回json", description = "返回json描述")
    public HelloWorld helloWord() {
        return helloWorld;
    }
}
